package com.zhong.scanerdemo.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;

import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class ScanerParameters {
	private List<NameValuePair> nameValuePairs = null;

	public ScanerParameters() {
		nameValuePairs = new ArrayList<NameValuePair>();
	}

	public List<NameValuePair> getNameValuePairs() {
		return nameValuePairs;
	}

	public void setNameValuePairs(List<NameValuePair> nameValuePairs) {
		this.nameValuePairs = nameValuePairs;
	}

	public void add(String key, String value) {
		NameValuePair nameValuePair = new BasicNameValuePair(key, value);
		nameValuePairs.add(nameValuePair);
	}

	public static ScanerParameters initParameter(String uid, String pwd,
			String source, String startDate, String method, String descr,
			String dutyOfficer, String driver, String carNum,
			String startingPoint, String destination, String scanResult) {
		ScanerParameters parameters = new ScanerParameters();

		try {
			parameters.add(KeyAndUrl.REQUEST_ID,
					URLEncoder.encode("500", KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.DUTY_OFFICER,
					URLEncoder.encode(dutyOfficer, KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.DRIVER,
					URLEncoder.encode(driver, KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.VEHICLE_NUM,
					URLEncoder.encode(carNum, KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.STARTING_POINT,
					URLEncoder.encode(startingPoint, KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.DESTINATION,
					URLEncoder.encode(destination, KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.SCAN_RESULT,
					URLEncoder.encode(scanResult, KeyAndUrl.HTTP_ENCODE));

			// 新增
			parameters.add(KeyAndUrl.UID,
					URLEncoder.encode(uid, KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.PASSWORD,
					URLEncoder.encode(MD5Util.MD5(pwd), KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.SOURCE,
					URLEncoder.encode(source, KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.START_DATA,
					URLEncoder.encode(startDate, KeyAndUrl.HTTP_ENCODE));
			//獲取當前時間上傳
			parameters.add(KeyAndUrl.END_DATE,
					URLEncoder.encode(DateUtil.getDate(), KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.TRANSPORT_METHOD,
					URLEncoder.encode(method, KeyAndUrl.HTTP_ENCODE));
			parameters.add(KeyAndUrl.DESCR,
					URLEncoder.encode(descr, KeyAndUrl.HTTP_ENCODE));
			
			

		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return parameters;
	}

	@Override
	public String toString() {
		return "ScanerParameters [nameValuePairs=" + nameValuePairs + "]";
	}

}
